<!doctype html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security"
      class="x-admin-sm">
<head>

    <th:block th:include="common/head::xadmin('登录')"/>
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <link rel="stylesheet" th:href="@{/static/css/login.css}">
</head>
<body class="login-bg">
<div class="login layui-anim layui-anim-up">
    <div class="message">BigFish</div>
    <div id="darkbannerwrap"></div>

    <form method="post" class="layui-form" th:action="@{/login}">
        <input name="username" placeholder="用户名" type="text" lay-verify="required" class="layui-input">
        <hr class="hr15">
        <input name="password" lay-verify="required" placeholder="密码" type="password" class="layui-input">
        <hr class="hr15">
        <div id="hs-box">

        </div>

        <hr class="hr15">
        <input value="登录" lay-submit lay-filter="login" style="width:100%;" type="submit">
        <hr class="hr20">
        <span style="color:red" th:if="${param.error}">用户或者密码错误，请重新输入!</span>
    </form>
</div>

<script>
    $(function () {
        layui.use('form', function () {
            var form = layui.form,
                box = document.querySelector('#hs-box');


            function loadHS() {
                $.get('/humanskill/image/001', {}, function (res, status) {
                    switch (res.type) {
                        case 'IMG':
                            box.innerHTML = '<div class="layui-input-inline" style="width: 200px;">\n' +
                                '<input name="hs-token" placeholder="验证码" type="text" class="layui-input" lay-verify="required"/>\n' +
                                '</div>\n' +
                                '<div class="layui-input-inline ">\n' +
                                '<img id="hs-img" src="' + 'data:image/jpg;base64,' + res.data + '"/>\n' +
                                '</div>'
                            box.querySelector('#hs-img').addEventListener('click', function () {
                                loadHS();
                            });
                            break;
                        case 'SLIDE':
                            console.log(res);
                            break;


                    }

                })
            }

            loadHS();

            form.on('submit(login)', function (data) {
                return true;
            });
        });
    })
</script>
</body>
</html>